﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Auction
{
    public partial class FSearchWorkOfArt : Form
    {
        FormBase frmSuper;
        WorkOfArt workFound = null;
        Validations valid = new Validations();
        private EDM_AuctionContainer context;
        public FSearchWorkOfArt(FormBase frmSuper, EDM_AuctionContainer context)
        {
            InitializeComponent();
            this.frmSuper = frmSuper;
            this.context = context;
        }
        private void rdbSearchById_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbSearchById.Checked)
            {
                grb_ID.Enabled = true;
                b_SearchWork.Enabled = true;
            }
            else
            {
                grb_ID.Enabled = false;
            }
        }

        private void rdbSearchByWorkName_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbSearchByWorkName.Checked)
            {
                grb_Name.Enabled = true;
                b_SearchWork.Enabled = true;
            }
            else
            {
                grb_Name.Enabled = false;
            }
        }

        private void b_SearchWork_Click(object sender, EventArgs e)
        {
            lblAdvNotFound.Visible=false;
            Lnk_showMoreData.Visible = false;
            workFound = null;
            if (rdbSearchById.Checked)
            {
                int id = valid.GetInt(t_id);
                try
                {
                    workFound = context.WorkOfArtSet.FirstOrDefault(w => w.idWorkOfArt == id);
                }
                catch (System.Exception)
                {
                    workFound = null;
                }
            }
            else if(rdbSearchByWorkName.Checked)
            {
                try
                {
                    workFound = context.WorkOfArtSet.FirstOrDefault(w => w.nameOfWork ==t_Name.ToString() );
                }
                catch (System.Exception)
                {
                    workFound = null;
                }
            }
            if (workFound != null)
            {
                ((FormBase)this.frmSuper).TransferWorkFound(workFound);
            }
            else
            {
                lblAdvNotFound.Visible = true;
            }
        }
    }
}
